package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.OrgResultMapper;
import com.yuwubao.uav.tool.service.OrgResultService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class OrgResultServiceImpl implements OrgResultService {

    private static final Logger logger = LogManager.getLogger(OrgResultServiceImpl.class.getName());

    @Resource
    private OrgResultMapper orgResultMapper;

    @Override
    public void clickOrgResult(PageData pageData) throws Exception {
        try{
            orgResultMapper.clickOrgResult(pageData);

        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void deleteOrgResult(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    orgResultMapper.deleteOrgResult(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateOrgResult(PageData pageData) throws Exception {
        try{
            orgResultMapper.updateOrgResult(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableOrgResult(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    orgResultMapper.disableOrEnableOrgResult(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableOrgResultType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    orgResultMapper.disableOrEnableOrgResultType(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addOrgResult(PageData pageData) throws Exception {
        try{
            orgResultMapper.addOrgResult(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listOrgResult(PageData pageData) throws Exception {
        try{
            return orgResultMapper.listOrgResult(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listOrgResultCount(PageData pageData) throws Exception {
        try{
            return orgResultMapper.listOrgResultCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    @Override
    public void deleteOrgResultType(PageData pageData) throws Exception {
        try{

            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");

            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    orgResultMapper.deleteOrgResultType(pageData);

                }
            }


        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateOrgResultType(PageData pageData) throws Exception {
        try{
            orgResultMapper.updateOrgResultType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void addOrgResultType(PageData pageData) throws Exception {
        try{
            String names = pageData.get("names") == null ? "" : pageData.getString("names");
            if (StringUtil.isNotNvlOrBlank(names)) {
                String[] nameArr = names.split(",");
                if (nameArr != null && nameArr.length>0) {
                    for (String name : nameArr) {
                        pageData.put("name",name);
                        orgResultMapper.addOrgResultType(pageData);
                    }
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listOrgResultType(PageData pageData) throws Exception {
        try{
            return orgResultMapper.listOrgResultType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listOrgResultTypeAll(PageData pageData) throws Exception {
        try{
            return orgResultMapper.listOrgResultTypeAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listOrgResultTypeCount(PageData pageData) throws Exception {
        try{
            return orgResultMapper.listOrgResultTypeCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

}
